const babelCore = require('@babel/core')

const code = `
  let foo = ['a','p','p','l','e']
  for (var i of foo) {
    console.log(i);
  }
`
const result = babelCore.transformSync(code,{
    plugins: ["@babel/plugin-transform-for-of"]
})

console.log(result.code);